/**
 * @file 05-rest-spread.ts
 * 
 * 1.3.5 使用REST属性解构对象
 * 1.3.6 使用REST处理可变数量的参数
 */

let guitar = { manufacturer: 'Ibanez', type: 'Jem 777', strings: 6 };

// // 原始的对象处理方式
// const manufacturer = guitar.manufacturer;
// const type = guitar.type;
// const strings = guitar.strings;

let { manufacturer: mark, type, strings } = guitar

console.log(guitar)
console.log(`mark: ${mark},type: ${type},strings: ${strings}`)

let { manufacturer, ...details } = guitar

console.log(`manufacturer: ${manufacturer},details: ${details.strings + details.type}`)

const instruments = ['Guitar', 'Violin', 'Oboe', 'Drums'];
/*
// 原始的数组解构方式
const gtr = instruments[0];
const violin = instruments[1];
const oboe = instruments[2];
const drums = instruments[3];
*/

let [gtr, violin, oboe, drums] = instruments;
console.log(instruments)
console.log(`gtr: ${gtr},violin: ${violin},oboe: ${oboe},drums: ${drums}`)

let [arg1, ...instrumentslice] = instruments;
console.log(instrumentslice[1]);

// Rest parameters demonstration
function PrintInstruments(log: string, ...instruments: string[]): void {
    console.log(log);
    instruments.forEach(instrument => {
        console.log(instrument);
    });
}

PrintInstruments('Music Shop Inventory', 'Guitar', 'Drums', 'Clarinet', 'Clavinova', 'Test');